/***************************************************************************

    debugstreams.cpp	- my logging class, see header

 ***************************************************************************/



#include "debugstreams.h"

#ifndef NDEBUG

DebugLevelType Debug::itsLevel = INFO;

Debug::Debug()
{
}

Debug::~Debug()
{
}

ostream& Debug::operator() (const DebugLevelType& Level)
{
  if (Level < itsLevel)
    {
      // just ignore these messages
      return nullstream; // a stream with no output, very quick
    }
  switch(Level)
    {
    case ALL:
      clog << "       : ";
      break;
    case MEM:
      clog << "    MEM : ";
      break;
    case FUNC:
    case LFUNC:
      clog << "  FUNC : ";
      break;
    case BLANK:
      break;
    case DEBUG: 
      cerr << "     DEBUG :";
      return cerr;
      break;
    case INFO:
    case LINFO:
    case RELEASE:
      clog << "  INFO : ";
      return clog;
      break;
    case PROGRESS:
      cout << "        ";
      return cout;
      break;
    case WARN:
      clog << "WARN   : " << ""; //^G is a beep 
      return clog;
      break;
    case ERR:
      cerr << "ERR    : " << ""; //^G is a beep
      return cerr;
      break;
    default:
      break;
    }
  return clog;
}

string Debug::printLevel()
{
  switch (itsLevel)
    {
    case ALL:
      return string("ALL");
      break;
    case DEBUG:
      return string("DEBUG");
      break;		
    case LINFO:
      return string("LINFO");
      break;	 
    case LFUNC:
      return string("LFUNC");
      break;	 
    case FUNC:
      return string("FUNC");
      break;	 
    case MEM:
      return string("MEM");
      break;	 
    case BLANK:
    case INFO:
      return string("INFO");
      break;	 
    case PROGRESS:
      return string("PROGRESS");
      break;	 
    case RELEASE:
      return string("RELEASE");
      break;	 
    case WARN:
      return string("WARN");
      break;	 
    case ERR:
      return string("ERR");
      break;	 
    default:
      return string("UNKNOWN!!!!!!");
    }
}

DebugLevelType Debug::getLevel() const
{
    return itsLevel;
}

void Debug::setLevel(const DebugLevelType& Level)
{
  itsLevel = Level;
  //clog << "   INFO: DebugLevel set to: " << printLevel() << endl;
}

#endif
